package com.shop.operator.controller;


import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.shop.domain.CustomSeller;
import com.shop.domain.PageResult;
import com.shop.model.Seller;
import com.shop.operator.service.OperatorSellerService;


@Controller
public class OperatorSellerAction {

	@Resource
	private OperatorSellerService operatorSellerService;
	/**
	 * 商品审核界面
	 * http://localhost:8080/Shopping/returnSeller.action
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/returnSeller")
	public String returnseller() throws Exception{
		return "forward:WEB-INF/operator/admin/seller_1.jsp";
	}
	
	
	
	/**
	 * 商家管理界面
	 * http://localhost:8080/Shopping/returnsellerManager.action
	 * @return
	 * @throws Exception
	 */
		@RequestMapping("/returnsellerManager")
		public String returnsellerManager() throws Exception{
			return "forward:WEB-INF/operator/admin/seller.jsp";
		}
		
	

	
	/**
	 * 条件查询
	 * http://localhost:8080/Shopping/findSellerByLike.action?page=1&size=5
	 * @param seller 客户端传递过来的商家信息
	 * @param page 页数
	 * @param size 每页大小
	 * @return
	 * @throws Exception
	 */
	@ResponseBody
	@RequestMapping("/findSellerByLike")
	public PageResult findSellerByLike(@RequestBody Seller seller,int page,int size) throws Exception{
		
		System.out.println("查询所有的商家分页");
		
		return this.operatorSellerService.findPage(seller,page, size);

	}
	
	/**
	 * 根据id查找商家的信息
	 * http://localhost:8080/Shopping/findOneById.action?id="baidu"
	 * @param id
	 * @return
	 * @throws Exception
	 */
	@ResponseBody
	@RequestMapping("/findOneById")
	public CustomSeller findOneById(String id) throws Exception{
		
		System.out.println("根据id查找商品id="+id);
		System.out.println(this.operatorSellerService.findAll(id));
		return this.operatorSellerService.findAll(id);	
	}
	
	@ResponseBody
	@RequestMapping("/updateStatus")
	public Map<String,String> updateStatus(String id,String status) throws Exception{
		
		Map<String,String> map = new HashMap<String, String>();
		try{
			this.operatorSellerService.updateStatus(id, status);
			System.out.println("修改状态id="+id+"修改转态status="+status);
			map.put("success", "true");
		}catch (Exception e) {
			e.printStackTrace();
			map.put("message", "更新失败");
		}
		
	    return map;
		
	}
	
}
